﻿using AutoMapper;
using MediatR;
using Traceability.APP.Application.Command.Pictures;
using Traceability.Damoin;
using Traceability.ErrorCode;
using Traceability.Infaseture;

namespace Traceability.APP.Application.CommandHadnLer.Prices
{
    public class AddpictureCommandHandLer : IRequestHandler<AddpictureCommand, APIResult<int>>
    {

        private readonly IBaseRepostiy<Picture> _picture;
        private readonly IMapper mapper;

        public AddpictureCommandHandLer(IBaseRepostiy<Picture> picture, IMapper mapper)
        {
            _picture = picture;
            this.mapper = mapper;
        }
        public async Task<APIResult<int>> Handle(AddpictureCommand request, CancellationToken cancellationToken)
        {
            APIResult<int> result = new APIResult<int>();
            var list = mapper.Map<Picture>(request);

            var res = await _picture.AddAsync(list);
            result.Code = ResultCode.Ok;
            result.Message = "照片添加成功";
            result.Data = res;
            return await Task.FromResult(result);
        }
    }
}
